package special;

import java.util.HashSet;
import static util.Auxiliary.*;
import java.util.Iterator;
import java.util.Stack;
import util.Pair;

/**
 * @author Grega
 */
public class Edge<V>
{
  public final V connectedTo;
  public final Pair label;

  public Edge(V connectedTo, Pair label)
  {
    this.connectedTo = connectedTo;
    this.label = label;
  }

  // returns amount of freeWeight of edge,
  // freeWeight(edge) = weight of edge - (bubble(v1)+bubble(v2)), p = (v1, v2)
  public static double freeWeight(double weight, Stack<Flower> v1,
          Stack<Flower> v2)
  {
    double temp = 0;
    Iterator<Flower> it = v1.iterator();
    while (it.hasNext()) {
      temp += it.next().width;
    }
    it = v2.iterator();
    while (it.hasNext()) {
      temp += it.next().width;
    }
    return weight - temp;
  }
	
	 // goes through all paired vertex-es, throw it from freeVertexSet
	public static boolean isPerfectMatching(int sizeV, HashSet<Pair> M)
  {
    HashSet<Integer> freeVertexSet = fillWithInt(sizeV);
    Iterator<Pair> it = M.iterator();
    Pair p;
    while (it.hasNext()) {
      p = it.next();
      if (!freeVertexSet.remove(p.v1)) {
        System.out.println("Warning: Vertex " + p.v1 + " in pairing conflict!");
      }
      if (!freeVertexSet.remove(p.v2)) {
        System.out.println("Warning: Vertex " + p.v2 + " in pairing conflict!");
      }
    }
    if (freeVertexSet.isEmpty()) {
      return true;
    }
    return false;
  }

}
